home *** CD-ROM | disk | FTP | other *** search
/ Run Magazine ReRun 1985 Winter / rerun-1985-winter.d64 / run assembler (.txt) < prev    next >
Commodore BASIC  |  2022-09-20  |  4KB  |  190 lines

  1. 10 poke 53281,1 : poke 53280,1 : print chr$(144)
  2. 20 gosub 4000
  3. 30 x=0
  4. 40 read a : if a=255 then 60
  5. 50 read b$ : read c : x=x+1 : goto 40
  6. 60 dim dec%(x),opcode$(x),byte%(x)
  7. 70 dim ad(255),s$(255),c$(255)
  8. 80 er=x-1
  9. 90 restore
  10. 100 for i=0 to x-1 : read dec%(i) : read opcode$(i) : read byte%(i)
  11. 110 next i
  12. 120 print chr$(146);chr$(147)
  13. 130 print "adrs"; tab(10);"opcode";tab(25);"operand"
  14. 140 for x=1 to 40 : print chr$(114); : next
  15. 150 print
  16. 160 rem ****************************
  17. 170 rem set address and input opcode
  18. 180 rem ****************************
  19. 190 sa=0 : print "press <return> to default to 49152"
  20. 200 n=0
  21. 210 input "starting addr";sa : if sa=0 then sa=49152
  22. 220 ba=sa
  23. 230 print sa;tab(10);
  24. 240 input oc$ : if oc$="q" then 760
  25. 250 c=0
  26. 260 if oc$=opcode$(c) then d%=dec%(c) : b%=byte%(c) : goto 290
  27. 270 c=c+1 : if c>er  then print tab(10);chr$(18);"error";chr$(146) : goto 230
  28. 280 goto 260
  29. 290 if b%=1 then poke sa,d% :  sa=sa+1
  30. 300 if b%=1 then s$(n)=oc$ : ad(n)=sa-1 : n=n+1 : goto 230
  31. 310 rem *************
  32. 320 rem enter operand
  33. 330 rem *************
  34. 340 print tab(25); : print chr$(145); : input opr$
  35. 350 ad(n)=sa : s$(n)=oc$ : c$(n)=opr$ : n=n+1
  36. 360 if left$(opr$,1)<>"$" then oper=val(opr$)
  37. 370 if left$(opr$,1)="$" then gosub 490
  38. 380 if oper >65535 then gosub 630 : oper=0:  goto 340
  39. 390 if oc$="bne" or oc$="beq" then gosub 700
  40. 400 if oper>255 and b% <3 then gosub 560: oper=0 : goto 340
  41. 410 if oper > 255 then gosub 640
  42. 420 rem ************
  43. 430 rem compile code
  44. 440 rem ************
  45. 450 if b%=2 then poke sa,d% : sa=sa + 1
  46. 460 if b%=2 then poke sa,oper : sa=sa+1 : oper=0 :  goto 230
  47. 470 poke sa,d%: sa=sa+1
  48. 480 poke sa,lb : sa=sa+1 : poke sa,hb : sa=sa+1 : oper=0 : goto 230
  49. 490 rem **********************
  50. 500 rem convert hex to decimal
  51. 510 rem **********************
  52. 520 h$=mid$(oper$,2)
  53. 530 for l=1 to len(h$) : hd=asc(mid$(h$,l,1))
  54. 540 oper=oper*16+hd-48+((hd>57)*7)
  55. 550 next l : return
  56. 560 rem **********
  57. 570 rem error trap
  58. 580 rem **********
  59. 590 print chr$(18);"error-must be less than 256"
  60. 600 for w=1 to 400 : next w : printchr$(146); : print chr$(145);
  61. 610 for x=1 to 27 : printchr$(32); : next
  62. 620 print chr$(157);chr$(157);chr$(145) :return
  63. 630 print chr$(18);"value over 65535 ($ffff)";chr$(146) : return
  64. 640 rem ************************
  65. 650 rem convert to 2 byte number
  66. 660 rem ************************
  67. 670 lb=oper-int(oper/256)*256
  68. 680 hb=int(oper/256)
  69. 690 return
  70. 700 rem *************
  71. 710 rem branch offset
  72. 720 rem *************
  73. 730 if sa > oper then oper= 254-(sa-oper)
  74. 740 if sa < oper then oper= (oper-sa)-2
  75. 750 return
  76. 760 rem **************
  77. 770 rem ending routine
  78. 780 rem **************
  79. 790 nb = sa-ba
  80. 800 print chr$(147)
  81. 810 for x=1 to 5 : print : next
  82. 820 input"save program(y/n)";an$
  83. 830 if an$="y" then 890
  84. 840 print : print : print "program is";nb;"bytes long"
  85. 850 print "to execute 'sys'";ba : print
  86. 860 input "(b)egin again or (e)nd";de$
  87. 870 if de$="b" then 120
  88. 880 print : print"end" : end
  89. 890 print chr$(147) : for x=1 to 5 : print : next
  90. 900 lb=ba-int(ba/256)*256 : hb=int(ba/256)
  91. 910 input "enter file name";nw$:nf$=nw$:nf$="0:"+nf$+str$(ba)+",p,w"
  92. 920 open2,8,2,nf$
  93. 930 print#2,chr$(lb)+chr$(hb);
  94. 940 for x=ba to sa-1: oc=peek(x)
  95. 950 print#2,chr$(oc);
  96. 960 next x
  97. 970 close2
  98. 980 nf$=""
  99. 990 nf$="0:" + nw$+",s,w"
  100. 1000 open 9,8,9,nf$
  101. 1010 for v=0 to n-1
  102. 1020 print#9,ad(v),s$(v),c$(v)
  103. 1030 next v
  104. 1040 close9
  105. 1050 goto 840
  106. 1060 rem ***********
  107. 1070 rem opcode data
  108. 1080 rem ***********
  109. 1090 data 24,clc,1
  110. 1100 data 32,jsr,3
  111. 1110 data 56,sec,1
  112. 1120 data 73,eor#,2
  113. 1130 data 76,jmp,3
  114. 1140 data 77,eor,3
  115. 1150 data 96,rts,1
  116. 1160 data 105,adc#,2
  117. 1170 data 108,(jmp),3
  118. 1180 data 109,adc,3
  119. 1190 data 121,adc-y,3
  120. 1200 data 125,adc-x,3
  121. 1210 data 129,(sta-x),2
  122. 1220 data 133,sta-z,2
  123. 1230 data 134,stx-z,2
  124. 1240 data 136,dey,1
  125. 1250 data 138,txa,1
  126. 1260 data 140,sty,3
  127. 1270 data 141,sta,3
  128. 1280 data 142,stx,3
  129. 1290 data 145,(sta-y),2
  130. 1300 data 148,sty-x,2
  131. 1310 data 152,tya,1
  132. 1320 data 157,sta-x,3
  133. 1330 data 153,sta-y,3
  134. 1340 data 154,txs,1
  135. 1350 data 160,ldy#,2
  136. 1360 data 161,(lda-x),2
  137. 1370 data 162,ldx#,2
  138. 1380 data 164,ldy-z,2
  139. 1390 data 165,lda-z,2
  140. 1400 data 166,ldx-z,2
  141. 1410 data 168,tay,1
  142. 1420 data 169,lda#,2
  143. 1430 data 170,tax,1
  144. 1440 data 172,ldy,3
  145. 1450 data 173,lda,3
  146. 1460 data 174,ldx,3
  147. 1470 data 177,(lda-y),2
  148. 1480 data 185,lda-y,3
  149. 1490 data 186,tsx,1
  150. 1500 data 188,ldy-x,3
  151. 1510 data 189,lda-x,3
  152. 1520 data 190,ldx-y,3
  153. 1530 data 192,cpy#,2
  154. 1540 data 193,(cmp-x),2
  155. 1550 data 196,cpy-z,2
  156. 1560 data 197,cmp-z,2
  157. 1570 data 198,dec-z,2
  158. 1580 data 200,iny,1
  159. 1590 data 201,cmp#,2
  160. 1600 data 202,dex,1
  161. 1610 data 204,cpy,3
  162. 1620 data 205,cmp,3
  163. 1630 data 206,dec,3
  164. 1640 data 208,bne,2
  165. 1650 data 221,cmp-x,3
  166. 1660 data 222,dec-x,3
  167. 1670 data 224,cpx#,2
  168. 1680 data 230,inc-z,2
  169. 1690 data 232,inx,1
  170. 1700 data 233,sbc#,2
  171. 1710 data 234,nop,1
  172. 1720 data 236,cpx,3
  173. 1730 data 237,sbc,3
  174. 1740 data 238,inc,3
  175. 1750 data 240,beq,2
  176. 1760 data 249,sbc-y,3
  177. 1770 data 253,sbc-x,3
  178. 1780 data 254,inc-x,3
  179. 1790 rem ************************
  180. 1800 rem add additional data here
  181. 1810 rem ************************
  182. 1820 data 255
  183. 4000 rem ******
  184. 4010 rem header
  185. 4020 rem ******
  186. 4030 print chr$(147)
  187. 4040 ld$="loading array" : for x=1 to 10 : print : next : h=20-len(ld$)/2
  188. 4050 print tab(h);chr$(18);ld$
  189. 4060 return
  190.